package com.vecspace.dayu.code.ui.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.dayu.code.consts.QueryElementType;
import com.vecspace.dayu.code.pojo.DataColumn;
import com.vecspace.dayu.code.ui.pojo.DataGridColumn;
import com.vecspace.dayu.code.ui.pojo.FormField;
import com.vecspace.dicttable.DictAll;
import com.vecspace.exception.HException;
import com.vecspace.utils.Assert;
import com.vecspace.utils.Convert;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;

public class ColumnVO extends DataColumn implements Cloneable{

	private static final long serialVersionUID = 8047450785843083312L;
	private DataColumn dataColumn;

    @JsonIgnore
    public DataColumn getDataColumn() {
        return dataColumn;
    }

    public ColumnVO(){

    }

    public ColumnVO(DataColumn dataColumn){
        if(dataColumn == null)return;
        this.dataColumn = dataColumn;
        this.setTableColumnId(dataColumn.getId());
        this.setDatatableId(dataColumn.getDatatableId());
        this.setColumnName(dataColumn.getColumnName());
        this.setColumnCaption(dataColumn.getColumnCaption());
        this.setColumnAliasName(dataColumn.getColumnAliasName());
        this.setDataType(dataColumn.getDataType());
        this.setDataLength(dataColumn.getDataLength());
        this.setDataScale(dataColumn.getDataScale());
        this.setUnit(dataColumn.getUnit());
        this.setMinCharLength(dataColumn.getMinCharLength());
        this.setMaxCharLength(dataColumn.getMaxCharLength());
        this.setMaxValue(dataColumn.getMaxValue());
        this.setMinValue(dataColumn.getMinValue());
        this.setCodeType(dataColumn.getCodeType());
        this.setRefTableName(dataColumn.getRefTableName());
        this.setRefIdColumn(dataColumn.getRefIdColumn());
        this.setRefNameColumn(dataColumn.getRefNameColumn());
        this.setRefNameColumnAliasName(dataColumn.getRefNameColumnAliasName());
        this.setCharsetType(dataColumn.getCharsetType());
        this.setTableColumnOrdnum(dataColumn.getOrdnum());
    }
    @JsonIgnore
    public DataColumn parseDataColumn(){
        DataColumn dataColumn = new DataColumn();
        dataColumn.setId(this.getTableColumnId());
        dataColumn.setDatatableId(this.getDatatableId());
        dataColumn.setColumnName(this.getColumnName());
        dataColumn.setColumnCaption(this.getColumnCaption());
        dataColumn.setColumnAliasName(this.getColumnAliasName());
        dataColumn.setDataType(this.getDataType());
        dataColumn.setDataLength(this.getDataLength());
        dataColumn.setDataScale(this.getDataScale());
        dataColumn.setUnit(this.getUnit());
        dataColumn.setMinCharLength(this.getMinCharLength());
        dataColumn.setMaxCharLength(this.getMaxCharLength());
        dataColumn.setMaxValue(this.getMaxValue());
        dataColumn.setMinValue(this.getMinValue());
        dataColumn.setCodeType(this.getCodeType());
        dataColumn.setRefTableName(this.getRefTableName());
        dataColumn.setRefIdColumn(this.getRefIdColumn());
        dataColumn.setRefNameColumn(this.getRefNameColumn());
        dataColumn.setRefNameColumnAliasName(this.getRefNameColumnAliasName());
        dataColumn.setCharsetType(this.getCharsetType());
        dataColumn.setOrdnum(this.getTableColumnOrdnum());
        return dataColumn;
    }

    public void putGridColumn(DataGridColumn gridColumn){
        if(gridColumn == null)return;
        Assert.throwz(this.tableColumnId.equals(gridColumn.getColumnId()), "gridColumn.ColumnId不匹配");
        this.setIsGridColumn(true);
        this.setGridColumnId(gridColumn.getId());
        this.setDatagridId(gridColumn.getDatagridId());
        //this.setColumnId              (gridColumn.  	  getColumnId              ());
        this.setColumnLabel(gridColumn.getColumnLabel());
        this.setGridColumnGroup(gridColumn.getColumnGroup());
        this.setColumnWidth(gridColumn.getColumnWidth());
        this.setCellTextType(gridColumn.getCellTextType());
        this.setFontStyle(gridColumn.getFontStyle());
        this.setHyperlink(gridColumn.getHyperlink());
        this.setRenderScript(gridColumn.getRenderScript());
        this.setVisibleStatus(gridColumn.getVisibleStatus());
        this.setFixed(gridColumn.getFixed());
        this.setMergeCell(gridColumn.getMergeCell());
        this.setEditAble(gridColumn.getEditAble());
        this.setInputElementType(gridColumn.getInputElementType());
        this.setEditMenu(gridColumn.getEditMenu());
        this.setAggregateFunc(gridColumn.getAggregateFunc());
        this.setAggregateGroup(gridColumn.getAggregateGroup());
        this.setQueryField(gridColumn.getQueryField());
        this.setQuerySqlOperator(gridColumn.getQuerySqlOperator());
        this.setQueryVisibleStatus(gridColumn.getQueryVisibleStatus());
        this.setQueryInputElementType(gridColumn.getQueryInputElementType());
        this.setQueryRequired(gridColumn.getQueryRequired());
        this.setQueryMultiValue(gridColumn.getQueryMultiValue());
        this.setGridColumnOrdnum(gridColumn.getOrdnum());
    }

    @JsonIgnore
    public DataGridColumn parseGridColumn(){
        DataGridColumn gridColumn = new DataGridColumn();
        gridColumn.setId(this.getGridColumnId());
        gridColumn.setDatagridId(this.getDatagridId());
        gridColumn.setColumnId(this.getTableColumnId());
        gridColumn.setColumnLabel(this.getColumnLabel());
        gridColumn.setColumnGroup(this.getGridColumnGroup());
        gridColumn.setColumnWidth(this.getColumnWidth());
        gridColumn.setCellTextType(this.getCellTextType());
        gridColumn.setFontStyle(this.getFontStyle());
        gridColumn.setHyperlink(this.getHyperlink());
        gridColumn.setRenderScript(this.getRenderScript());
        gridColumn.setVisibleStatus(this.getVisibleStatus());
        gridColumn.setFixed(this.getFixed());
        gridColumn.setMergeCell(this.getMergeCell());
        gridColumn.setEditAble(this.getEditAble());
        gridColumn.setInputElementType(this.getInputElementType());
        gridColumn.setEditMenu(this.getEditMenu());
        gridColumn.setAggregateFunc(this.getAggregateFunc());
        gridColumn.setAggregateGroup(this.getAggregateGroup());
        gridColumn.setQueryField(this.getQueryField());
        gridColumn.setQuerySqlOperator(this.getQuerySqlOperator());
        gridColumn.setQueryVisibleStatus(this.getQueryVisibleStatus());
        gridColumn.setQueryInputElementType(this.getQueryInputElementType());
        gridColumn.setQueryRequired(this.getQueryRequired());
        gridColumn.setQueryMultiValue(this.getQueryMultiValue());
        gridColumn.setOrdnum(this.getGridColumnOrdnum());
        return gridColumn;
    }

    public void putFormField(FormField formField){
        if(formField == null)return;
        Assert.throwz(this.tableColumnId.equals(formField.getColumnId()), "formField.columnId不匹配");
        this.setIsFormField(true);
        this.setFormId(formField.getFormId());
        this.setInputTip(formField.getInputTip());
        this.setColumnLabel(formField.getColumnLabel());
        this.setFormColumnGroup(formField.getColumnGroup());
        this.setNewRow(formField.getNewRow());
        this.setColSpan(formField.getColSpan());
        this.setRowSpan(formField.getRowSpan());
        this.setFormElementType(formField.getFormElementType());
        this.setRequired(formField.getRequired());
        this.setValidationRules(formField.getValidationRules());
        this.setFormFieldOrdnum(formField.getOrdnum());
    }

    @JsonIgnore
    public FormField parseFormField(){
        FormField formField = new FormField();
        formField.setId(formField.getFormId());
        formField.setFormId(this.getFormId());
        formField.setColumnId(this.getTableColumnId());
        formField.setInputTip(this.getInputTip());
        formField.setColumnLabel(this.getColumnLabel());
        formField.setColumnGroup(this.getFormColumnGroup());
        formField.setNewRow(this.getNewRow());
        formField.setColSpan(this.getColSpan());
        formField.setRowSpan(this.getRowSpan());
        formField.setFormElementType(this.getFormElementType());
        formField.setRequired(this.getRequired());
        formField.setValidationRules(this.getValidationRules());
        formField.setOrdnum(this.getFormFieldOrdnum());
        return formField;
    }

    /** ---------------------------------------------------------------*/
    private boolean isGridColumn;
    private boolean isFormField;

    public boolean getIsGridColumn() {
        return isGridColumn;
    }

    public void setIsGridColumn(boolean gridColumn) {
        isGridColumn = gridColumn;
    }

    public boolean getIsFormField() {
        return isFormField;
    }

    public void setIsFormField(boolean formField) {
        isFormField = formField;
    }

    /** ------------------------DataColumn--------------------------------*/
    private Long tableColumnId;
    /**逻辑ID*/
    public Long getTableColumnId(){
        return tableColumnId;
    }
    /**逻辑ID*/
    public void setTableColumnId(Long value){
        this.tableColumnId = value;
    }

//
//    private Long datatableId;
//    /**表ID*/
//    @Column(name = "DATATABLE_ID")
//    public Long getDatatableId(){
//        return datatableId;
//    }
//    /**表ID*/
//    public void setDatatableId(Long value){
//        this.datatableId = value;
//    }
//
//    private String columnName;
//    /**字段名*/
//    @Column(name = "COLUMN_NAME")
//    public String getColumnName(){
//        return columnName;
//    }
//    /**字段名*/
//    public void setColumnName(String value){
//        this.columnName = value;
//    }
//
//    private String columnCaption;
//    /**字段中文名*/
//    @Column(name = "COLUMN_CAPTION")
//    public String getColumnCaption(){
//        return columnCaption;
//    }
//    /**字段中文名*/
//    public void setColumnCaption(String value){
//        this.columnCaption = value;
//    }
//
//    private String columnAliasName;
//    /**字段别名*/
//    @Column(name = "COLUMN_ALIAS_NAME")
//    public String getColumnAliasName(){
//        return columnAliasName;
//    }
//    /**字段别名*/
//    public void setColumnAliasName(String value){
//        this.columnAliasName = value;
//    }
//    private String dataType;
//    /**数据类型*/
//    @Column(name = "DATA_TYPE")
//    public String getDataType(){
//        return dataType;
//    }
//    /**数据类型*/
//    public void setDataType(String value){
//        this.dataType = value;
//    }
//
//    private Integer dataLength;
//    /**数据长度*/
//    @Column(name = "DATA_LENGTH")
//    public Integer getDataLength(){
//        return dataLength;
//    }
//    /**数据长度*/
//    public void setDataLength(Integer value){
//        this.dataLength = value;
//    }
//
//    private Integer dataScale;
//    /**小数位数*/
//    @Column(name = "DATA_SCALE")
//    public Integer getDataScale(){
//        return dataScale;
//    }
//    /**小数位数*/
//    public void setDataScale(Integer value){
//        this.dataScale = value;
//    }
//
//    private String unit;
//    /**数量单位*/
//    @Column(name = "UNIT_")
//    public String getUnit(){
//        return unit;
//    }
//    /**数量单位*/
//    public void setUnit(String value){
//        this.unit = value;
//    }
//
//    private Integer minCharLength;
//    /**最大字符数*/
//    @Column(name = "MIN_CHAR_LENGTH")
//    public Integer getMinCharLength(){
//        return minCharLength;
//    }
//    /**最大字符数*/
//    public void setMinCharLength(Integer value){
//        this.minCharLength = value;
//    }
//
//    private Integer maxCharLength;
//    /**最少字符数*/
//    @Column(name = "MAX_CHAR_LENGTH")
//    public Integer getMaxCharLength(){
//        return maxCharLength;
//    }
//    /**最少字符数*/
//    public void setMaxCharLength(Integer value){
//        this.maxCharLength = value;
//    }
//
//    private BigDecimal maxValue;
//    /**最大值*/
//    @Column(name = "MAX_VALUE")
//    public BigDecimal getMaxValue(){
//        return maxValue;
//    }
//    /**最大值*/
//    public void setMaxValue(BigDecimal value){
//        this.maxValue = value;
//    }
//
//    private BigDecimal minValue;
//    /**最小值*/
//    @Column(name = "MIN_VALUE")
//    public BigDecimal getMinValue(){
//        return minValue;
//    }
//    /**最小值*/
//    public void setMinValue(BigDecimal value){
//        this.minValue = value;
//    }
//
//    private String codeType;
//    /**代码类型*/
//    @Column(name = "CODE_TYPE")
//    public String getCodeType(){
//        return codeType;
//    }
//    /**代码类型*/
//    public void setCodeType(String value){
//        this.codeType = value;
//    }
//
//    private String refTableName;
//    /**参考表名*/
//    @Column(name = "REF_TABLE_NAME")
//    public String getRefTableName(){
//        return refTableName;
//    }
//    /**参考表名*/
//    public void setRefTableName(String value){
//        this.refTableName = value;
//    }
//
//    private String refIdColumn;
//    /**参考表ID字段*/
//    @Column(name = "REF_ID_COLUMN")
//    public String getRefIdColumn(){
//        return refIdColumn;
//    }
//    /**参考表ID字段*/
//    public void setRefIdColumn(String value){
//        this.refIdColumn = value;
//    }
//
//    private String refNameColumn;
//    /**参考表名称字段*/
//    @Column(name = "REF_NAME_COLUMN")
//    public String getRefNameColumn(){
//        return refNameColumn;
//    }
//    /**参考表名称字段*/
//    public void setRefNameColumn(String value){
//        this.refNameColumn = value;
//    }
//
//    private String refNameColumnAliasName;
//    /**参考表名称字段别名*/
//    @Column(name = "REF_NAME_COLUMN_ALIAS_NAME")
//    public String getRefNameColumnAliasName(){
//        return refNameColumnAliasName;
//    }
//    /**参考表名称字段别名*/
//    public void setRefNameColumnAliasName(String value){
//        this.refNameColumnAliasName = value;
//    }
//
//    private String charsetType;
//    /**字符集*/
//    @Column(name = "CHARSET_TYPE")
//    public String getCharsetType(){
//        return charsetType;
//    }
//    /**字符集*/
//    public void setCharsetType(String value){
//        this.charsetType = value;
//    }

    private Integer tableColumnOrdnum;
    /**顺序号*/
    public Integer getTableColumnOrdnum(){
        return tableColumnOrdnum;
    }
    /**顺序号*/
    public void setTableColumnOrdnum(Integer value){
        this.tableColumnOrdnum = value;
    }

    /** ------------------------------------------------GridColumn--------------------------------------------------------*/
    private Long gridColumnId;
    public Long getGridColumnId(){
        return gridColumnId;
    }
    /**逻辑ID*/
    public void setGridColumnId(Long value){
        this.gridColumnId = value;
    }

    protected Long datagridId;
    /**数据表ID*/
    public Long getDatagridId(){
        return datagridId;
    }
    /**数据表ID*/
    public void setDatagridId(Long value){
        this.datagridId = value;
    }

    private String gridColumnGroup;
    /**表头分组*/
    public String getGridColumnGroup(){
        return gridColumnGroup;
    }
    /**表头分组*/
    public void setGridColumnGroup(String value){
        this.gridColumnGroup = value;
    }

    private Integer columnWidth;
    /**列宽*/
    public Integer getColumnWidth(){
        return columnWidth;
    }
    /**列宽*/
    public void setColumnWidth(Integer value){
        this.columnWidth = value;
    }

    private String cellTextType;

    /**显示样式*/
    public String getCellTextType(){
        return cellTextType;
    }
    /**显示样式*/
    public void setCellTextType(String value){
        this.cellTextType = value;
    }

    public String getCellTextTypeCaption(){
        return DictAll.getCachedItemName(DataGridColumn.CellTextTypeCode, cellTextType);
    }

    private String fontStyle;
    /**字体*/
    public String getFontStyle(){
        return fontStyle;
    }
    /**字体*/
    public void setFontStyle(String value){
        this.fontStyle = value;
    }

    private Boolean hyperlink;
    /**超链接*/
    public Boolean getHyperlink(){
        if(hyperlink == null) return false;
        return hyperlink;
    }
    /**超链接*/
    public void setHyperlink(Boolean value){
        this.hyperlink = value;
    }

    private String renderScript;
    /**自定义显示内容*/
    public String getRenderScript(){
        return renderScript;
    }
    /**自定义显示内容*/
    public void setRenderScript(String value){
        this.renderScript = value;
    }

    private Boolean visibleStatus;
    /**显示状态*/
    public Boolean getVisibleStatus(){
        if(visibleStatus == null) return false;
        return visibleStatus;
    }
    /**显示状态*/
    public void setVisibleStatus(Boolean value){
        this.visibleStatus = value;
    }

    private Boolean fixed;
    /**是否固定列*/
    public Boolean getFixed(){
        if(fixed == null) return false;
        return fixed;
    }
    /**是否固定列*/
    public void setFixed(Boolean value){
        this.fixed = value;
    }

    private Boolean mergeCell;
    /**合并单元格*/
    public Boolean getMergeCell(){
        if(mergeCell == null) return false;
        return mergeCell;
    }
    /**合并单元格*/
    public void setMergeCell(Boolean value){
        this.mergeCell = value;
    }

    private Boolean editAble;
    /**单元格可编辑*/
    public Boolean getEditAble(){
        if(editAble == null) return false;
        return editAble;
    }
    /**单元格可编辑*/
    public void setEditAble(Boolean value){
        this.editAble = value;
    }

    private String inputElementType;
    /**编辑输入框类型*/
    public String getInputElementType(){
        return inputElementType;
    }
    /**编辑输入框类型*/
    public void setInputElementType(String value){
        this.inputElementType = value;
    }

    @Transient
    public String getInputElementTypeCaption(){
        return DictAll.getCachedItemName(DataGridColumn.InputElementTypeCode, inputElementType);
    }
    /**下拉菜单 0否 1是*/
    private Boolean editMenu;
    /**下拉菜单 0否 1是*/
    public Boolean getEditMenu(){
        if(editMenu == null) return false;
        return editMenu;
    }
    /**下拉菜单 0否 1是*/
    public void setEditMenu(Boolean value){
        this.editMenu = value;
    }

    private String aggregateFunc;
    /**聚合函数*/
    public String getAggregateFunc() {
        return aggregateFunc;
    }
    /**聚合函数*/
    public void setAggregateFunc(String aggregateFunc) {
        this.aggregateFunc = aggregateFunc;
    }
    public String getAggregateFuncCaption() {
        return aggregateFunc;
    }

    private Boolean aggregateGroup;
    /**是否分组字段 0否 1是*/
    public Boolean getAggregateGroup() {
        if(aggregateGroup == null) return false;
        return aggregateGroup;
    }
    /**是否分组字段 0否 1是*/
    public void setAggregateGroup(Boolean aggregateGroup) {
        this.aggregateGroup = aggregateGroup;
    }

    /**是否为查询项,0否，1是*/
    private boolean isQueryField;
    /**是否为查询项,0否，1是*/
    public Boolean getQueryField() {
        return isQueryField;
    }
    /**是否为查询项,0否，1是*/
    public void setQueryField(Boolean queryField) {
        if(queryField == null){
            isQueryField = false;
        }else {
            isQueryField = queryField;
        }
    }

    private String querySqlOperator;

    public static String QuerySqlOperatorCode = "DAYU-CODE-016";

    /**查询项条件匹配类型*/
    public String getQuerySqlOperator() {
        return querySqlOperator;
    }
    /**查询项条件匹配类型*/
    public void setQuerySqlOperator(String querySqlOperator) {
        this.querySqlOperator = querySqlOperator;
    }

    public String getQuerySqlOperatorCaption(){
        return DictAll.getCachedItemName(DataGridColumn.QuerySqlOperatorCode, querySqlOperator);
    }
    public static String showStatusCode = "DAYU-CODE-018";
    private Boolean queryVisibleStatus;
    /**查询项显示状态,0默认不显示，1默认显示，3始终显示*/
    public Boolean getQueryVisibleStatus() {
        if(queryVisibleStatus == null) return false;
        return queryVisibleStatus;
    }
    /**查询项显示状态,0默认不显示，1默认显示，3始终显示*/
    public void setQueryVisibleStatus(Boolean queryVisibleStatus) {
        this.queryVisibleStatus = queryVisibleStatus;
    }


    private String queryInputElementType;
    public static final String QueryInputElementTypeCode = "DAYU-CODE-012";

    /**查询项输入框类型*/
    public String getQueryInputElementType() {
        return queryInputElementType;
    }
    /**查询项输入框类型*/
    public void setQueryInputElementType(String queryInputElementType) {
        this.queryInputElementType = queryInputElementType;
    }
    public String getQueryInputElementTypeCaption(){
        return DictAll.getCachedItemName(DataGridColumn.QueryInputElementTypeCode, queryInputElementType);
    }

    private Boolean queryRequired;
    /**查询项是否必填，0否，1是*/
    public Boolean getQueryRequired() {
        if(queryRequired == null) return false;
        return queryRequired;
    }
    /**查询项是否必填，0否，1是*/
    public void setQueryRequired(Boolean queryRequired) {
        this.queryRequired = queryRequired;
    }

    private Boolean queryMultiValue;
    /**查询项是否可多选，0否，1是*/
    public Boolean getQueryMultiValue() {
        if(queryMultiValue == null) return false;
        return queryMultiValue;
    }
    /**查询项是否可多选，0否，1是*/
    public void setQueryMultiValue(Boolean queryMultiValue) {
        this.queryMultiValue = queryMultiValue;
    }

    private Integer gridColumnOrdnum;
    /**顺序号*/
    public Integer getGridColumnOrdnum(){
        return gridColumnOrdnum;
    }
    /**顺序号*/
    public void setGridColumnOrdnum(Integer value){
        this.gridColumnOrdnum = value;
    }

    /** ------------------------FormField--------------------------------*/
    private Long formFieldId;
    public Long getFormFieldId(){
        return formFieldId;
    }
    /**逻辑ID*/
    public void setFormFieldId(Long value){
        this.formFieldId = value;
    }

    private Long formId;
    /**表单ID*/
    public Long getFormId(){
        return formId;
    }
    /**表单ID*/
    public void setFormId(Long value){
        this.formId = value;
    }

    private String inputTip;
    /**输入提示*/
    public String getInputTip(){
        return inputTip;
    }
    /**输入提示*/
    public void setInputTip(String value){
        this.inputTip = value;
    }

    private String columnLabel;
    /**标签*/
    public String getColumnLabel(){
        return columnLabel;
    }
    /**标签*/
    public void setColumnLabel(String value){
        this.columnLabel = value;
    }

    private String formColumnGroup;
    /**表单分组*/
    public String getFormColumnGroup(){
        return formColumnGroup;
    }
    /**表单分组*/
    public void setFormColumnGroup(String value){
        this.formColumnGroup = value;
    }


    private Boolean newRow;
    /**强制新起一行*/
    public Boolean getNewRow(){
        if(newRow == null) return false;
        return newRow;
    }
    /**强制新起一行*/
    public void setNewRow(Boolean value){
        this.newRow = value;
    }

    private Integer colSpan;
    /**列数*/
    public Integer getColSpan(){
        if(colSpan == null || colSpan <= 0){
            return 1;
        }
        return colSpan;
    }
    /**列数*/
    public void setColSpan(Integer value){
        if(value == null || value <= 0){
            value = 1;
        }
        this.colSpan = value;
    }

    private Integer rowSpan;
    /**行数*/
    public Integer getRowSpan(){
        return rowSpan;
    }
    /**行数*/
    public void setRowSpan(Integer value){
        this.rowSpan = value;
    }

    private String formElementType;

    public static String FormElementTypeCode = "DAYU-CODE-011";

    /**编辑输入框类型*/
    public String getFormElementType(){
        return formElementType;
    }
    /**编辑输入框类型*/
    public void setFormElementType(String value){
        this.formElementType = value;
    }

    public String getFormElementTypeCaption(){
        return DictAll.getCachedItemName(FormElementTypeCode, formElementType);
    }

    private Boolean required;
    /**是否必填*/
    public Boolean getRequired(){
        if(required == null) return false;
        return required;
    }
    /**是否必填*/
    public void setRequired(Boolean value){
        this.required = value;
    }

    private String validationRules;
    /**验证规则*/
    public String getValidationRules(){
        return validationRules;
    }
    /**验证规则*/
    public void setValidationRules(String value){
        this.validationRules = value;
    }

    /**验证规则*/
    private String validationRulesCaption;
    public String getValidationRulesCaption() {
        return validationRulesCaption;
    }
    public void setValidationRulesCaption(String validationRulesCaption) {
        this.validationRulesCaption = validationRulesCaption;
    }

    private Integer formFieldOrdnum;
    /**顺序号*/
    public Integer getFormFieldOrdnum(){
        return formFieldOrdnum;
    }
    /**顺序号*/
    public void setFormFieldOrdnum(Integer value){
        this.formFieldOrdnum = value;
    }

    /** --------------------------------------------------------*/



    public String getFilterDataType(){
        if(QueryElementType.DATE_YEAR.equalsIgnoreCase(this.getQueryInputElementType())){
            return "date-year";
        }else  if(QueryElementType.DATE_MONTH.equalsIgnoreCase(this.getQueryInputElementType())){
            return "date-month";
        }
        String jsType = "string";
        String javaType = this.getJavaType();
        if(getIsNumber()) {
            jsType = "number";
        }
        if("Boolean".equals(javaType)) {
            jsType = "boolean";
        }
        if("LocalDate".equals(javaType) || "LocalDateTime".equals(javaType)) {
            jsType = "date";
        }
        return jsType;
    }

    public boolean getSearchFieldDroplist(){
        if(QueryElementType.SELECT.equalsIgnoreCase(this.getQueryInputElementType()))return true;
        return false;
    }

    public boolean getSearchFieldCheckboxes(){
        if(QueryElementType.CHECKBOXES.equalsIgnoreCase(this.getQueryInputElementType()))return true;
        return false;
    }
    /**返回聚合字段(一个原始字段如果有多个聚合函数，则返回列表中对应多个字段)
	 *比如salary字段,使用 sum,agv,max 三个聚合函数 则返回三个聚合字段
     */
    public List<DataColumn> getAggregateColumns(){
        List<DataColumn> aggColumns = new ArrayList<>();
        String aggFuncs = getAggregateFunc();
        if(StringUtils.isBlank(aggFuncs)) return aggColumns;

        String[] funcArr = aggFuncs.split(",|;|，|；");
        for(String aggFunc : funcArr){
            aggFunc = aggFunc.trim().toUpperCase();
            if(aggFunc.length() == 0)continue;
            String label = DictAll.getItemName("DAYU-CODE-022", aggFunc);
            String expression;
            String aliasName = "";
            String dataType = this.getDataType();
            int dataScale = this.getDataScale();
            int dataLen = this.getDataLength();
            if("COUNT".equalsIgnoreCase(aggFunc)){
                expression = "count(*)";
                aliasName = getColumnName()+"_ROWS_COUNT";
                dataType = "number";
                dataLen = 8;
                dataScale = 0;
            }else if("COUNT_DISTINCT".equalsIgnoreCase(aggFunc)){
                expression = String.format("count(distinct(%s))",getColumnName());
                aliasName = getColumnName()+"_DISTINCT_COUNT";
                dataType = "number";
                dataLen = 8;
                dataScale = 0;
            }else{
                expression = String.format("%s(%s)", aggFunc, getColumnName());
                aliasName = getColumnName()+"_"+aggFunc;
                if("SUM".equalsIgnoreCase(aggFunc)){
                    if(!getIsNumber()){
                        throw new HException("只有数字类型的字段才能设置为SUM(统计)字段");
                    }
                    dataType = "number";
                    dataLen = 15;
                }else if("AVG".equalsIgnoreCase(aggFunc)){
                    if(!getIsNumber()){
                        throw new HException("只有数字类型的字段才能设置为AVG(统计)字段");
                    }
                    dataType = "number";
                    dataLen = 15;
                    if(dataScale == 0) {//整数的平均值，取一位小数。小数的平均值，按原字段的小数位。
                        dataScale = 1;
                    }
                }else if("MAX".equalsIgnoreCase(aggFunc)){
                }else if("MIN".equalsIgnoreCase(aggFunc)){
                }
            }
            aliasName = aliasName.replace("__", "_");//getColumnName()+"_ROWS_COUNT"; 有可能会出现两个下划线
            DataColumn aggColumn = new DataColumn();
            aggColumn.setAggregateFunc(aggFunc.toUpperCase());
            aggColumn.setColumnName(expression);
            aggColumn.setColumnCaption(label);
            aggColumn.setColumnAliasName(aliasName);
            aggColumn.setDataType(dataType);
            aggColumn.setDataLength(dataLen);
            aggColumn.setDataScale(dataScale);
            aggColumns.add(aggColumn);
        }
        return aggColumns;
    }

    @Transient
    public String getAlign(){
        if(this.getIsNumber())return "right";
        if(StringUtils.isNotBlank(this.getCodeType()))return "center";
        String javaType = this.getJavaType();
        if("LocalDate".equals(javaType))return "center";
        if("LocalDateTime".equals(javaType))return "center";
        if("Boolean".equals(javaType))return "center";
        return "left";
    }
    
    public int getGridColumnWidth() {
    	int width = Convert.toInt(getColumnWidth(), 0);
    	if(width == 0) {
    		int dataLen = Convert.toInt(this.getDataLength(), 0);
    		String javaType = this.getJavaType();
    		if("LocalDate".equals(javaType)) {
    			width = 100;
    		}
    		if("LocalDateTime".equals(javaType)) {
    			width = 140;
    		}
    		if("Boolean".equals(javaType)) {
    			width = 100;
    		}
    		if("String".equals(javaType)) {
    			if(dataLen <= 10) {
    				width = 120;
    			}else if(dataLen <= 50) {
    				width = 150;
    			}else if(dataLen <= 100) {
    				width = 180;
    			}else if(dataLen <= 200) {
    				width = 220;
    			}else {
    				width = 220;
    			}
    		}
    		if(this.getIsNumber()) {
    			width = 100;
    		}
    		if(StringUtils.isNotBlank(this.getCodeType())) {
    			width = 100;
    		}
    	}
    	if(width == 0) {
    		width = 120;
    	}
    	return width;
    }

//    private String expression;
//    /**select字段的函数表达式，比如SUM(AMOUNT) COUNT(*)*/
//    public String getExpression() {
//        return expression;
//    }
//    /**select字段的函数表达式*/
//    public void setExpression(String expression) {
//        this.expression = expression;
//    }

    @Override
    public ColumnVO clone() throws CloneNotSupportedException {
        return (ColumnVO)super.clone();
    }
}
